#include "GraphBuilder.h"

using namespace analyzer;

GraphBuilder::GraphBuilder(void) : graph(NULL)
{
	
}

GraphBuilder::~GraphBuilder(void)
{
	// empty destructor
}

std::pair<Vertex,bool> GraphBuilder::addVertex(std::string vertexName, FileType fileType) {

	if(vertricesNames.find(vertexName) != vertricesNames.end()) {
		return std::make_pair(vertricesNames[vertexName], false);
	}

	Vertex v = boost::add_vertex(*graph);

	boost::property_map<Graph, boost::vertex_name_t>::type vertexNames = boost::get(boost::vertex_name_t(), *graph);
	boost::property_map<Graph, vertex_type_t>::type vertexTypes = boost::get(vertex_type_t(), *graph);

	boost::put(vertexNames, v, vertexName);
	boost::put(vertexTypes, v, fileType);

	vertricesNames.insert(std::pair<std::string, Vertex>(vertexName, v));
	
	return std::make_pair(vertricesNames[vertexName], true);
}

void GraphBuilder::addEdge(Vertex fromVertex, Vertex toVertex) {

	boost::add_edge(fromVertex, toVertex, *graph);
}

Vertex GraphBuilder::findEdge(std::string vertexName) {

	return vertricesNames[vertexName];
}

void GraphBuilder::createNewGraph() {

	graph = new Graph();
	vertricesNames.clear();
}

Graph* GraphBuilder::getGraph() {

	return graph;
}
